<?php

namespace IDock\Insurance\TPBX\Response;

use IDock\Http\Request;
use IDock\Http\Response;

class AllTPBXResponse extends Response
{

    protected $status = '';

    protected $logicStatus = '';

    public function resolve(): Response
    {
        $body = $this->getBody();
        $body = iconv('GBK','UTF-8//IGNORE',$body);
        if ($this->printer) {
            $this->printer = new $this->printer;
        }
        if ($body) {
            $body = json_decode($body,true);
            $returnCode = $body['code'] ?? '';
            $message = $body['msg'] ?? '';
            $this->setBody($body);
            if ($returnCode != '0000') {
                $this->setError($message);
                return  $this;
            }
        }

        return $this;
    }


    /**
     * @return string
     */
    public function getState(): string
    {
        return $this->get('state','');
    }

    /**
     * @return string
     */
    public function getMsg(): string
    {
        return $this->get('msg','');
    }


}
